<template>
  <el-dialog title="请选择要从此任务中分角出去的奖金项：" :close-on-click-modal="false" :visible.sync="visible" width="50vw">
    <div>
      <el-table :data="jjxXq" @selection-change="handleSelectionChange" border width="100%" height="300px">
        <el-table-column type="selection" width="55px" header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="jjxName" header-align="center" align="center" label="奖金项名称"
                         min-width="150"></el-table-column>
        <el-table-column prop="jjxJe" header-align="center" align="center" label="奖金项金额" min-width="150">
          <template slot-scope="scope">
            {{ $formatNum(jjxJeXq[scope.row.jjxId].jjZe) }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dataFormSubmit()">分解任务</el-button>
      <el-button type="primary" plain @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {saveDecompose} from '@/api/jiangjin/jiangjinfpjjfpdjb'

export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        jjxXq: '',
        jjxJeXq: ''
      },
      jjxXq: [],
      jjxJeXq: {},
      multipleSelection: []
    }
  },
  methods: {
    //初始化
    csh() {
      this.fzData = [];
      this.jjxList = [];
      this.cityOptions = [];
      this.dataForm = {
        id: 0,
        jjxXq: '',
        jjxJeXq: ''
      };
    },
    init(r) {
      this.csh();
      this.dataForm = r;
      this.jjxXq = JSON.parse(r.jjxXq);
      this.jjxJeXq = JSON.parse(r.jjxJeXq);
      this.visible = true;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 表单提交
    dataFormSubmit() {
      if (this.multipleSelection.length == 0) {
        this.$notify.closeAll();
        this.$notify.error('请选择奖金项');
      }
      if (this.multipleSelection.length == this.jjxXq.length) {
        this.$notify.closeAll();
        this.$notify.error('您不可以选择所有的奖金项');
      }
      let id = this.dataForm.id;
      let idlist = [];
      for (var i in this.multipleSelection) {
        idlist.push(this.multipleSelection[i].jjxId);
      }
      this.$confirm('分解后将变成两个任务，是否执行！', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return saveDecompose(id,idlist.join(","))
      }).then(data => {
        this.$message.closeAll()
        this.$message.success('分解成功');
        this.$emit('refreshDataList');
        this.visible = false;
      })

    },
  }
}
</script>
<style scoped>
.el-divider {
  background-color: #fff
}
</style>
